package com.jintian.smart.kernel.security.service;

import com.jintian.smart.base.api.security.entity.ReloadItemEntity;
import com.jintian.smart.base.api.security.entity.ReloadResultEntity;
import com.jintian.smart.kernel.core.support.SmartReloadItem;
import com.jintian.smart.kernel.core.support.SmartReloadResult;
import com.jintian.smart.kernel.security.mapper.ReloadItemMapper;
import com.jintian.smart.kernel.security.mapper.ReloadResultMapper;
import com.jintian.smart.kernel.security.reload.AbstractSmartReloadCommand;
import jakarta.annotation.Resource;
import com.jintian.smart.kernel.common.util.SmartBeanUtil;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * reload 操作
 */
@Component
public class ReloadCommand extends AbstractSmartReloadCommand {
    @Resource
    private ReloadItemMapper reloadItemMapper;

    @Resource
    private ReloadResultMapper reloadResultMapper;

    /**
     * 读取数据库中SmartReload项
     *
     * @return List<ReloadItem.md>
     */
    @Override
    public List<SmartReloadItem> readReloadItem() {
        List<ReloadItemEntity> reloadItemEntityList = reloadItemMapper.all();
        return SmartBeanUtil.copyList(reloadItemEntityList, SmartReloadItem.class);
    }


    /**
     * 保存reload结果
     *
     * @param smartReloadResult
     */
    @Override
    public void handleReloadResult(SmartReloadResult smartReloadResult) {
        ReloadResultEntity reloadResultEntity = SmartBeanUtil.copy(smartReloadResult, ReloadResultEntity.class);
        reloadResultMapper.insert(reloadResultEntity);
    }
}
